package cn.lanqiao.springboot.controller;

import cn.lanqiao.springboot.entity.Menu;
import cn.lanqiao.springboot.service.MenuService;
import cn.lanqiao.springboot.util.CurrentUserUtil;
import cn.lanqiao.springboot.util.Result;
import cn.lanqiao.springboot.vo.QueryMenuVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    MenuService menuService;

    @PostMapping("/list")
    public Result getList() {
        int roleId = CurrentUserUtil.get().getRoleId();
        return Result.success(menuService.getList(roleId));
    }

    @GetMapping("/roleList/{roleId}")
    public Result getRoleList(@PathVariable int roleId) {
        return Result.success(menuService.getList(roleId));
    }

    @PostMapping("/pageList")
    public Result getPageList(@RequestBody QueryMenuVO queryMenuVO) {
        PageHelper.startPage(queryMenuVO.getCurrentPage(), queryMenuVO.getPageSize());
        List<Menu> menuList = menuService.getALLMenuList(queryMenuVO);
        PageInfo<Menu> pageInfo = new PageInfo<>(menuList);
        return Result.success(pageInfo);
    }

    @PostMapping("/allList")
    public Result getALLList(@RequestBody QueryMenuVO queryMenuVO) {
        List<Menu> menuList = menuService.getALLMenuList(queryMenuVO);
        return Result.success(menuList);
    }
}
